package adapter;

import java.util.ArrayList;

import utils.NavigationDrawerItem;

import com.example.lastprojectbeautiplus.R;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class NavDrawerListAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<NavigationDrawerItem> navDrawerItems;

	public NavDrawerListAdapter(Context context,
			ArrayList<NavigationDrawerItem> navDrawerItems) {
		this.context = context;
		this.navDrawerItems = navDrawerItems;
	}

	@Override
	public int getCount() {
		return navDrawerItems.size();
	}

	@Override
	public Object getItem(int position) {
		return navDrawerItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater mInflater = (LayoutInflater) context
					.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater
					.inflate(R.layout.slide_menu_list_item, null);
		}

		ImageView categoryIcon = (ImageView) convertView
				.findViewById(R.id.cate_icon);
		TextView categoryRow = (TextView) convertView
				.findViewById(R.id.cate_row);
		DisplayMetrics metrics = convertView.getResources().getDisplayMetrics();
		int width;
		width = metrics.widthPixels;
		categoryIcon.getLayoutParams().height = width / 10;
		categoryIcon.getLayoutParams().width = width / 10;
		RelativeLayout.LayoutParams layoutPramsRow = new RelativeLayout.LayoutParams(
				categoryRow.getLayoutParams());

		categoryRow.setText(navDrawerItems.get(position).getMenuRow());

		if (navDrawerItems.get(position).getIcon() != -1) {
			categoryIcon.setImageResource(navDrawerItems.get(position)
					.getIcon());
			// hardcode
			layoutPramsRow.setMargins(120, 0, 0, 0);
			categoryRow.setLayoutParams(layoutPramsRow);
			categoryIcon.setVisibility(View.VISIBLE);
			// layoutPramsIcon.setMargins(0, 0, 0, 0);
			// categoryIcon.setLayoutParams(layoutPramsIcon);
		} else if (navDrawerItems.get(position).getIcon() == -1) {
			// categoryIcon.setImageResource(R.drawable.cate_icon_next);
			// hardcode
			layoutPramsRow.setMargins(210, 0, 0, 0);
			categoryRow.setLayoutParams(layoutPramsRow);
			categoryIcon.setVisibility(View.GONE);
			// layoutPramsIcon.setMargins(80, 0, 0, 0);
			// categoryIcon.setLayoutParams(layoutPramsIcon);
		}
		return convertView;
	}

}
